home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / applets / commissi / commissi.jav < prev    next >
Text File  |  1995-12-19  |  30KB  |  1,158 lines

  1. import java.applet.*;
  2. import java.awt.*;
  3.  
  4. public class CommissionsAppBeta extends Applet {
  5.     final int number_of_brokers = 33;
  6.     final int THRESHOLD = 32000;
  7.     TextField price_obj;
  8.     TextField shares_obj;
  9.     TextField[] values;
  10.     Label[] brokers;
  11.     Label[] phones;
  12.     Checkbox is_stock;
  13.     Checkbox is_option;
  14.     CheckboxGroup stock_option;
  15.     String[] names;
  16.     int[] names_index;
  17.     double[] commisions;
  18.     public void init() {
  19.         int i, j, k;
  20.         String label_name1, label_name2;
  21.         values = new TextField[number_of_brokers];
  22.         brokers = new Label[number_of_brokers];
  23.         phones = new Label[number_of_brokers];
  24.         names = new String[number_of_brokers];
  25.         names_index = new int[number_of_brokers];
  26.         commisions = new double[number_of_brokers];
  27.         stock_option = new CheckboxGroup();
  28.         names[0]  = "Andrew Peck            1-800-221-5873";
  29.         names[1]  = "Aufhauser              1-800-368-3668";
  30.         names[2]  = "Barry Murphy           1-800-221-2111";
  31.         names[3]  = "Brown                  1-800-822-2021";
  32.         names[4]  = "ETrade                 1-800-786-2575";
  33.         names[5]  = "Jack White             1-800-909-6777";
  34.         names[6]  = "Kennedy Cabot          1-800-252-0090";
  35.         names[7]  = "Lombard                1-800-688-3462";
  36.         names[8]  = "Muriel Siebert         1-800-995-7880";
  37.         names[9]  = "National Discount      1-800-888-3999";
  38.         names[10] = "Pacific Brokerage      1-800-421-8395";
  39.         names[11] = "Scottsdale             1-800-888-1980";
  40.         names[12] = "Stock Cross            1-800-225-6196";
  41.         names[13] = "York Securities        1-800-221-3154";
  42.         names[14] = "Ceres Securities       1-800-669-3900";
  43.         names[15] = "Washington             1-800-843-9838";
  44.         names[16] = "Midwood                1-800-643-9663";
  45.         names[17] = "RJ Forbes              1-800-754-7687";
  46.         names[18] = "RTG Richards           1-800-285-3500";
  47.         names[19] = "Regal                  1-800-786-9000";
  48.         names[20] = "Wall Street            1-800-487-2339";
  49.                 names[21] = "Accutrade              1-800-882-4887"; 
  50.                 names[22] = "WhiteHall              1-800-223-5023"; 
  51.                 names[23] = "J Boxford              1-800-656-1776"; 
  52.                 names[24] = "Newport                1-800-999-3278"; 
  53.                 names[25] = "Bidwell                1-800-547-6337"; 
  54.                 names[26] = "Charles Schwab         1-800-442-5111";
  55.                 names[27] = "Fidelity               1-800-544-7272"; 
  56.                 names[28] = "Fleet                  1-800-221-8210"; 
  57.                 names[29] = "Olde                   1-800-872-6533";
  58.         names[30] = "Marsh Block            1-800-366-1500";
  59.         names[31] = "Quick & Reilly         1-800-456-4049";
  60.         names[32] = "Vanguard               1-800-662-7447";
  61.         add("Is_stock", is_stock = new Checkbox("Stock or..."));
  62.         add("Is_option", is_option = new Checkbox("Option trade?"));
  63.         add("PriceLabel", new Label("How much is the price per unit? (in $.c)"));
  64.         add("Price", price_obj = new TextField("", 10));
  65.         add("SharesLabel", new Label("How many units to trade?"));
  66.         add("Shares", shares_obj = new TextField("", 10));
  67.         is_stock.setCheckboxGroup(stock_option);
  68.         is_option.setCheckboxGroup(stock_option);
  69.         stock_option.setCurrent(is_stock);
  70.         is_stock.setState(true);
  71.         for(i = 0; i < number_of_brokers; i++) {
  72.             label_name1 = "broker".concat(new Integer(i).toString());
  73.             add(label_name1, brokers[i] = new Label(""));
  74.             label_name2 = label_name1.concat("phone");
  75.             add(label_name2, phones[i] = new Label(""));
  76.             label_name2 = label_name1.concat("values");
  77.             add(label_name2, values[i] = new TextField("", 10));
  78.         }
  79.                 for(i = 0; i < number_of_brokers; i++) {
  80.                         names_index[i] = i;
  81.                         commisions[i] = -1.0f;
  82.                 }
  83.                 for(i = 0; i < number_of_brokers; i++)
  84.                         for(j = number_of_brokers - 1; i < j; j--)
  85.                                if(names[names_index[j]].compareTo(names[names_index[i]]) < 0) {
  86.                                         k = names_index[i];
  87.                                         names_index[i] = names_index[j];
  88.                                         names_index[j] = k;
  89.                                 }
  90.                 for(i = 0; i < number_of_brokers; i++)
  91.                         values[i].setText(" ");
  92.                 for(i = 0; i < number_of_brokers; i++) {
  93.                         brokers[i].setText(names[names_index[i]].substring(0, 18));
  94.                         phones[i].setText(names[names_index[i]].substring(23, 37));
  95.         }
  96.     }
  97.     public synchronized void layout() {
  98.         int i;
  99.         resize(500, 110 + 30 * number_of_brokers);
  100.         if(0 < countComponents()) {
  101.             getComponent(0).reshape(150, 10, 100, 30);
  102.             getComponent(1).reshape(250, 10, 110, 30);
  103.             getComponent(2).reshape(75, 40, 200, 30);
  104.             getComponent(3).reshape(330, 40, 80, 30);
  105.             getComponent(4).reshape(75, 70, 300, 30);
  106.             getComponent(5).reshape(330, 70, 80, 30);
  107.             for(i = 0; i < number_of_brokers; i++) {
  108.                 getComponent(3 * i + 6).reshape(75, 110 + 30 * i, 125, 30);
  109.                 getComponent(3 * i + 7).reshape(200, 110 + 30 * i, 150, 30);
  110.                 getComponent(3 * i + 8).reshape(330, 110 + 30 * i, 80, 30);
  111.             }
  112.         }
  113.     }
  114.     public void compute() {
  115.         int i, j, k;
  116.         for(i = 0; i < number_of_brokers; i++) {
  117.             names_index[i] = i;
  118.             commisions[i] = -1.0;
  119.         }
  120.         if(stock_option.getCurrent() == is_stock)
  121.             compute_stock();
  122.         if(stock_option.getCurrent() == is_option)
  123.             compute_options();
  124.         for(i = 0; i < number_of_brokers; i++)
  125.             for(j = number_of_brokers - 1; i < j; j--)
  126.                 if(names[names_index[j]].compareTo(names[names_index[i]]) < 0) {
  127.                     k = names_index[i];
  128.                     names_index[i] = names_index[j];
  129.                     names_index[j] = k;
  130.                 }
  131.         for(i = 0; i < number_of_brokers; i++)
  132.             if(commisions[names_index[i]] < 0.0f)
  133.                 values[i].setText(" ");
  134.             else
  135.                 values[i].setText(new Double(commisions[names_index[i]]).toString());
  136.     }
  137.     public void compute_stock() {
  138.             double price, shares;
  139.         double fee, princ, min, max;
  140.         int i;
  141.         try {
  142.             price_obj.setText(price_obj.getText().replace(',', '.'));
  143.             shares_obj.setText(shares_obj.getText().replace(',', '.'));
  144.             price = Double.valueOf(price_obj.getText()).doubleValue();
  145.             shares = Double.valueOf(shares_obj.getText()).doubleValue();
  146.  
  147.             {
  148.               princ = shares * price;
  149.               if(princ < THRESHOLD) {
  150.                 fee = 40.0f;
  151.                 if(shares < 500.0f)
  152.                   fee = fee + 0.08f * shares;
  153.                 if((500.0f <= shares) && (shares < 1000.0f))
  154.                   fee = fee + 0.065f * shares;
  155.                 if((1000.0f <= shares) && (shares < 2500.0f))
  156.                   fee = fee + 0.05f * shares;
  157.                 if(2500.0f <= shares)
  158.                   fee = fee + 0.04f * shares;
  159.               } else {
  160.                 fee = 0.03f * shares;
  161.                 if(fee < 100.0f)
  162.                   fee = 100.0f;
  163.               };
  164.               commisions[0]= fee;
  165.             }
  166.             
  167.             {
  168.               princ = shares * price;
  169.               if(princ < THRESHOLD) {
  170.                 if(price < 1.0f)
  171.                   fee = 25.0f + 0.03f * shares;
  172.                 else {
  173.                   if(shares < 400.0f)
  174.                 fee = 24.99f;
  175.                   if((400.0f <= shares) && (shares < 500.0f))
  176.                 fee = 34.99f;
  177.                   if((500.0f <= shares) && (shares < 600.0f)) {
  178.                 fee = 40.99f;
  179.                 if(30.0f < price)
  180.                   fee = fee - 1.0f;
  181.                   };
  182.                   if((600.0f <= shares) && (shares < 700.0f)) {
  183.                 fee = 49.0f;
  184.                 if(price < 10.0f)
  185.                   fee = fee - 3.0f;
  186.                 if(price < 5.0f)
  187.                   fee = fee - 4.01f;
  188.                   };
  189.                   if((700.0f <= shares) && (shares < 800)) {
  190.                 fee = 52.99f;
  191.                 if(price < 50.0f)
  192.                   fee = fee - 2.0f;
  193.                 if(price < 20.0f)
  194.                   fee = fee - 1.0f;
  195.                 if(price < 10.0f)
  196.                   fee = fee - 2.0f;
  197.                 if(price < 5.0f)
  198.                   fee = fee - 6.0f;
  199.                   };
  200.                   if((800 <= shares) && (shares < 900.0f)) {
  201.                 fee = 59.0f;
  202.                 if(price < 10.0f)
  203.                   fee = fee - 6.0f;
  204.                 if(price < 5.0f)
  205.                   fee = fee - 11.01f;
  206.                   };
  207.                   if((900.0f <= shares) && (shares < 1000.0f)) {
  208.                 fee = 63.0f;
  209.                 if(price < 20.0f)
  210.                   fee = fee - 4.0f;
  211.                 if(price < 10.0f)
  212.                   fee = fee - 6.0f;
  213.                 if(price < 5.0f)
  214.                   fee = fee - 11.0f;
  215.                   };
  216.                   if((1000.0f <= shares) && (shares <= 5000.0f)) {
  217.                 fee = 70.0f;
  218.                 if(price < 30.0f)
  219.                   fee = fee - 2.0f;
  220.                 if(price < 20.0f)
  221.                   fee = fee - 9.0f;
  222.                 if(price < 10.0f)
  223.                   fee = fee - 6.0f;
  224.                 if(price < 5.0f)
  225.                   fee = fee - 11.0f;
  226.                 fee = fee + 0.066667f * (shares - 1000.0f);
  227.                   };
  228.                   if(5000.0f < shares)
  229.                 fee = 0.03f * shares;
  230.                 };
  231.               } else {
  232.                 fee = 0.02f * shares;
  233.                 if(fee < 34.0f)
  234.                   fee = 34.0f;
  235.               };
  236.               fee = fee + 2.5f;
  237.               commisions[1]= fee;
  238.             }
  239.             
  240.             {
  241.               double[] prices = {1.0f, 
  242.                         3.0f,
  243.                         10.0f,
  244.                         20.0f,
  245.                         25.0f,
  246.                         30.0f,
  247.                         99999999999.9f
  248.                         };
  249.               double[] costs = {0.01f,
  250.                            0.02f,
  251.                            0.035f,
  252.                            0.045f,
  253.                            0.055f,
  254.                            0.065f,
  255.                            0.075f
  256.                        };
  257.               for(i = 0; i < 7; i++)
  258.                 if(price < prices[i])
  259.                   break;
  260.               fee = 25.0f + shares * costs[i];
  261.               fee = fee + 2.0f;
  262.               commisions[2]= fee;
  263.             }
  264.             
  265.             {
  266.               fee = 29.0f;
  267.               if (5000.0f < shares)
  268.                 fee = fee + 0.01f * shares;
  269.               commisions[3]= fee;
  270.             }
  271.             
  272.             {
  273.               fee = 25.0f;
  274.               if(5000.0f < shares)
  275.                 fee = fee + 0.0075f * shares;
  276.               commisions[4]= fee;
  277.             }
  278.             
  279.             {
  280.               fee = 33.0f;
  281.               if(shares < 2000.0f)
  282.                 fee = fee + 0.03f * shares;
  283.               else 
  284.                 fee = fee + 0.02f * shares;
  285.               commisions[5]= fee;
  286.             }
  287.             
  288.             {
  289.               if(shares < 100.0f)
  290.                 fee = 20.0f;
  291.               if((100.0f <= shares) && (shares < 2000.0f))
  292.                 fee = 0.05f * shares;
  293.               if((2000.0f <= shares) && (shares < 5000.0f))
  294.                 fee = 0.03f * shares;
  295.               if(5000.0f <= shares)
  296.                 fee = 0.02f * shares;
  297.               if((fee < 30.0f) && (100.0f <= shares))
  298.                 fee = 30.0f;
  299.               fee = fee + 3.0f;
  300.               commisions[6]= fee;
  301.             }
  302.             
  303.             {
  304.               if(price < 1.0f)
  305.                 fee = 25.0f + 0.0275f * shares * price;
  306.               else {
  307.                 fee = 0.02f * shares;
  308.                 if(fee < 34.0f)
  309.                   fee = 34.0f;
  310.               };
  311.               fee = fee + 2.5f;
  312.               commisions[7]= fee;
  313.             }
  314.             
  315.             {
  316.               double base, rate;
  317.               double[] principles = {2500.0f,
  318.                             6000.0f,
  319.                             22000.0f,
  320.                             50000.0f,
  321.                             500000.0f,
  322.                             9999999999999.9f
  323.                         };
  324.               double[] bases = {21.0f,
  325.                            36.0f,
  326.                            56.0f,
  327.                            73.0f,
  328.                            114.0f,
  329.                            194.0f
  330.                        };
  331.               double[] perc = {0.0132f,
  332.                           0.0042f,
  333.                           0.0023f,
  334.                           0.0016f,
  335.                           0.0008f,
  336.                           0.0006f
  337.                       };
  338.               princ = shares * price;
  339.               if(princ < THRESHOLD) {
  340.                 for(i = 0; i < 6; i++)
  341.                   if(principles[i] < princ)
  342.                 continue;
  343.                   else
  344.                 break;
  345.                 base = bases[i] + perc[i] * princ;
  346.                 if(shares <= 1000.0f)
  347.                   min = 0.057f * shares;
  348.                 else
  349.                   min = 0.057f * 1000.0f + (shares - 1000.0f) * 0.028f;
  350.                 if(shares <= 100.0f)
  351.                   max = 0.45f * shares;
  352.                 else
  353.                   max = 0.45f * 100.0f + (shares - 100.0f) * 0.47f;
  354.                 fee = base;
  355.                 if(fee < min)
  356.                   fee = min;
  357.                 if(max < fee)
  358.                   fee = max;
  359.                 if(fee < 37.5f)
  360.                   fee = 37.5f;
  361.               } else {
  362.                 fee = shares * 0.03f;
  363.                 if(fee < 75.0f)
  364.                   fee = 75.0f;
  365.               };
  366.               commisions[8]= fee;
  367.             }
  368.             
  369.             {
  370.               fee = 30.0f;
  371.               if(5000.0f < shares) 
  372.                 fee = fee + 0.01f * shares;
  373.               fee = fee + 3.0f;
  374.               commisions[9]= fee;
  375.             }
  376.             
  377.             {
  378.               fee = 25.0f;
  379.               if(1000.0f < shares)
  380.                 fee = fee + 0.01f * (shares - 1000.0f);
  381.               fee = fee + 4.0f;
  382.               commisions[10]= fee;
  383.             }
  384.             
  385.             {
  386.               princ = shares * price;
  387.               if(princ < THRESHOLD) {
  388.                 fee = 35.0f;
  389.                 if(price < 1.0f)
  390.                   fee = fee + 0.025f * price * shares;
  391.                 else {
  392.                   if(1000.0f < shares) {
  393.                 fee = fee + 0.04f * (shares - 1000.0f);
  394.                 shares = 1000.0f;
  395.                   };
  396.                   if(price <= 10.0f) {
  397.                 if(300.0f < shares)
  398.                   fee = fee + 0.05f * (shares - 300.0f);
  399.                   } else {
  400.                 if(100.0f < shares)
  401.                   fee = fee + 0.05f * (shares - 100.0f);
  402.                   };
  403.                 };
  404.                 fee = fee * 0.90f;
  405.               } else {
  406.                 fee = 50.0f;
  407.                 if(1000.0f < shares)
  408.                   fee = fee + 0.025f * (shares - 1000.0f);
  409.               };
  410.               commisions[11]= fee;
  411.             }
  412.             
  413.             {
  414.               fee = 25.0f + 0.085f * shares;
  415.               commisions[12]= fee;
  416.             }
  417.             
  418.             {
  419.               fee = 33.0f + 0.02f * shares;
  420.               commisions[13]= fee;
  421.             }
  422.             
  423.             {
  424.               fee = 18.0f;
  425.               commisions[14]= fee;
  426.             }
  427.             
  428.             {
  429.               fee = 25.0f;
  430.               if(5000.0f < shares)
  431.                 fee = fee + 0.01f * shares;
  432.               fee = fee + 3.0f;
  433.               commisions[15]= fee;
  434.             }
  435.             
  436.             {
  437.               fee = 36.5f;
  438.               if(5000.0f < shares)
  439.                 fee = 11.0f + 0.15f * shares;
  440.               commisions[16]= fee;
  441.             }
  442.             
  443.             {
  444.               fee = 0.015f * shares;
  445.               if(fee < 35.0f)
  446.                 fee = 35.0f;
  447.               commisions[17]= fee;
  448.             }
  449.             
  450.             {
  451.               fee = 0.015f * shares;
  452.               if(fee < 33.0f)
  453.                 fee = 33.0f;
  454.               commisions[18]= fee;
  455.             }
  456.             
  457.             {
  458.               if(shares < 1000.0f)
  459.                 fee = 25.0f;
  460.               else
  461.                 fee = 20.0f;
  462.               commisions[19]= fee;
  463.             }
  464.             
  465.             {
  466.               fee = 40.0f + 0.03f * shares;
  467.               commisions[20]= fee;
  468.             }
  469.             
  470.             {
  471.               fee = 0.03f * shares;
  472.               if(fee < 48.0f)
  473.                 fee = 48.0f;
  474.               commisions[21]= fee;
  475.             }
  476.             
  477.             {
  478.               fee = 0.125f * shares;
  479.               if(fee < 50.0f)
  480.                 fee = 50.0f;
  481.               commisions[22]= fee;
  482.             }
  483.             
  484.             {
  485.               fee = 20.0f;
  486.               if(5000.0f < shares)
  487.                 fee = fee + 0.01f * shares;
  488.               fee = fee + 3.0f;
  489.               commisions[23]= fee;
  490.             }
  491.             
  492.             {
  493.               double[] sharess = {100.0f, 
  494.                         200.0f, 
  495.                         300.0f, 
  496.                         800.0f, 
  497.                         900.0f,
  498.                         100.00f,
  499.                         1100.0f,
  500.                         1200.0f,
  501.                         1300.0f,
  502.                         1400.0f,
  503.                         1500.0f,
  504.                         1600.0f,
  505.                         1700.0f,
  506.                         1800.0f,
  507.                         1900.0f,
  508.                         2000.00f, 
  509.                         999999999.0f
  510.                           };
  511.               double[] prices = {30.0f,  
  512.                          35.0f,  
  513.                          35.0f,  
  514.                          40.0f,  
  515.                          45.0f,
  516.                          50.0f,  
  517.                          51.0f,  
  518.                          52.0f,  
  519.                          53.0f,  
  520.                          54.0f,  
  521.                          55.0f,  
  522.                          56.0f,  
  523.                          57.0f,  
  524.                          58.0f,  
  525.                          59.0f, 
  526.                          60.0f, 
  527.                          -99.99f
  528.                          };
  529.               for(i = 0; i < 17; i++)
  530.                 if(sharess[i] < shares)
  531.                   continue;
  532.                 else
  533.                   break;
  534.               fee = prices[i];
  535.               commisions[24]= fee;
  536.             }
  537.             
  538.             {
  539.               double[] prices = {10.0f,
  540.                         20.0f,
  541.                         30.0f,
  542.                         999999.9f
  543.                         };
  544.               double[] costs = {0.05f,
  545.                         0.06f,
  546.                            0.07f,
  547.                            0.08f
  548.                        };
  549.               if(price < 1.0f) {
  550.                 fee = 0.05f * shares * price;
  551.                 if(fee < 20.0f)
  552.                   fee = 20.0f;
  553.               } else {
  554.                 fee = 20.0f;
  555.                 if(500.0f < shares) {
  556.                   fee = fee + 0.03f * (shares - 500.0f);
  557.                   shares = 500.0f;
  558.                 };
  559.                 for(i = 0; i < 4; i++)
  560.                   if(prices[i] < price)
  561.                 continue;
  562.                   else
  563.                 break;
  564.                 fee = fee + shares * costs[i];
  565.                 fee = fee + 1.25f;
  566.               };
  567.               commisions[25]= fee;
  568.             }
  569.             
  570.             {
  571.               double[] principles = { 2500.0f,
  572.                              6250.0f,
  573.                              20000.0f,
  574.                              50000.0f,
  575.                              500000.0f,
  576.                              9999999999.9f
  577.                          };
  578.               double[] bases = { 30.0f,
  579.                         56.0f,
  580.                         76.0f,
  581.                         100.0f,
  582.                         155.0f,
  583.                         255.0f
  584.                        };
  585.               double[] perc = {0.017f,
  586.                           0.0066f,
  587.                           0.0034f,
  588.                           0.0022f,
  589.                           0.0011f,
  590.                           0.0009f
  591.                         };
  592.               princ = shares * price;
  593.               for(i = 0; i < 6; i++)
  594.                 if(principles[i] < princ)
  595.                   continue;
  596.                 else
  597.                   break;
  598.               fee = bases[i] + perc[i] * princ;
  599.               if(1000.0f < shares)
  600.                 if(price < 5.0f)
  601.                   min = 90.0f + 0.04f * (shares - 1000.0f);
  602.                 else
  603.                   min = 90.0f + 0.05f * (shares - 1000.0f);
  604.               else
  605.                 min = 0.09f * shares;
  606.               if(shares < 100.0f)
  607.                 max = 55.0f;
  608.               else
  609.                 max = 55.0f + 0.55f * (shares - 100.0f);
  610.               if(max < fee)
  611.                 fee = max;
  612.               if(fee < min)
  613.                 fee = min;
  614.               if(fee < 39.0f)
  615.                 fee = 39.0f;
  616.               commisions[26]= fee;
  617.             }
  618.             
  619.             {
  620.               double[] principles = { 2500.0f,
  621.                              6000.0f,
  622.                              22000.0f,
  623.                              50000.0f,
  624.                              500000.0f,
  625.                              9999999999.9f
  626.                          };
  627.               double[] bases = { 29.5f,
  628.                         55.5f,
  629.                         75.5f,
  630.                         99.5f,
  631.                         154.5f,
  632.                         254.5f
  633.                        };
  634.               double[] perc = {0.017f,
  635.                           0.0066f,
  636.                           0.0034f,
  637.                           0.0022f,
  638.                           0.0011f,
  639.                           0.0009f
  640.                         };
  641.               princ = shares * price;
  642.               for(i = 0; i < 6; i++)
  643.                 if(principles[i] < princ)
  644.                   continue;
  645.                 else
  646.                   break;
  647.               fee = bases[i] + perc[i] * princ;
  648.               if(1000.0f < shares)
  649.                 min = 85.0f + 0.04f * (shares - 1000.0f);
  650.               else
  651.                 min = 0.085f * shares;
  652.               if(shares < 100.0f)
  653.                 max = 54.0f;
  654.               else
  655.                 max = 54.0f + 0.55f * (shares - 100.0f);
  656.               if(0.5f * princ < max)
  657.                 max = 0.5f * princ;
  658.               if(max < fee)
  659.                 fee = max;
  660.               if(fee < min)
  661.                 fee = min;
  662.               if(fee < 38.0f)
  663.                 fee = 38.0f;
  664.               commisions[27]= fee;
  665.             }
  666.             
  667.             {
  668.               princ = shares * price;
  669.               if(price < 1.0f)
  670.                 fee = 34.87f + .0412056f * princ;
  671.               else {
  672.                 if(princ <= 3000.0f)
  673.                   fee = 18.48f + .01232f * princ;
  674.                 if((3000.0f < princ) && (princ < 7000.0f))
  675.                   fee = 36.96f + 0.0061611f * princ;
  676.                 if((7000.0f < princ) && (princ < 27000.0f))
  677.                   fee = 58.52f + 0.0030811f * princ;
  678.                 if(27000.0f < princ)
  679.                   fee = 58.52f + 0.0030811f * princ;
  680.               }
  681.               if(shares <= 600.0f)
  682.                 min = 0.08217f * shares;
  683.               else
  684.                 min = (0.08217f * 600) + .0410256f * (shares - 600);
  685.               max = Math.floor((shares + 99.0f) / 100.0f) * 46.2f;
  686.               if(max < fee)
  687.                 fee = max;
  688.               if(fee < min)
  689.                 fee = min;
  690.               if(fee < 37.0f)
  691.                 fee = 37.0f;
  692.               fee = fee + 1.50f;
  693.               commisions[28]= fee;
  694.             }
  695.             
  696.             {
  697.               double lots;
  698.               lots = Math.floor((shares + 99.0f) / 100.0f);
  699.               if(price < 1.0f) {
  700.                 fee = 15.00f + 0.03f * shares;
  701.                 if(fee < 20.00f) 
  702.                   fee = 20.0f;
  703.               };
  704.               if((1.0f<= price) && (price <= 5.0f))
  705.                 if(shares < 500)
  706.                   fee = 15.0f + 5.0f * lots;
  707.                 else
  708.                   fee = 40.0f + 0.025f * (shares - 500);
  709.               if(5.0f<= price) {
  710.                 fee = 0.00f;
  711.                 if(500.0f <= shares) {
  712.                   fee  = 0.05f * (shares - 500);
  713.                   lots = 5.0f;
  714.                 };
  715.                 if(price <= 20.0f)
  716.                   fee = fee + 30.00f + 10.00f * lots;
  717.                 else
  718.                   if(3.0f <= lots)
  719.                 fee = fee + 80.0f + 10.0f * (lots - 3);
  720.                   else
  721.                 fee = fee + 20.0f + 20.0f * lots;
  722.               }
  723.               commisions[29]= fee;
  724.             }
  725.             
  726.             {
  727.               double[] principles = { 2500.0f,
  728.                              20000.0f,
  729.                              30000.0f,
  730.                              300000.0f,
  731.                              9999999999.9f
  732.                          };
  733.               double[] bases = { 12.0f,
  734.                         22.0f,
  735.                         82.0f,
  736.                         142.0f,
  737.                         -1.0f
  738.                        };
  739.               double[] perc = {0.013f,
  740.                           0.009f,
  741.                           0.006f,
  742.                           0.004f,
  743.                           0.004f
  744.                         };
  745.               double lots;
  746.               princ = shares * price;
  747.               if(price < 1.0f) {
  748.                 if(princ < 1000.0f)
  749.                   fee = 0.084f * princ;
  750.                 if((1000.0f <= princ) && (princ < 10000.0f))
  751.                   fee = 34.0f + 0.05f * princ;
  752.                 if(10000.0f <= princ)
  753.                   fee = 134.0f + 0.04f * princ;
  754.               } else {
  755.                 for(i = 0; i < 6; i++)
  756.                   if(principles[i] < princ)
  757.                 continue;
  758.                   else
  759.                 break;
  760.                 fee = bases[i] + perc[i] * princ;
  761.                 lots = Math.floor(shares / 100.0f);
  762.                 if(lots < 11.0f)
  763.                   fee = fee + 6.0f * lots;
  764.                 else
  765.                   fee = fee + 60.0f + 4.0f * (lots - 10.0f);
  766.               };
  767.               if(princ < 5000.0f)
  768.                 fee = fee * 1.3022f;
  769.               else
  770.                 fee = fee * 1.4705f;
  771.               fee = fee * 0.4f;
  772.               if(fee < 25.0f)
  773.                 fee = 25.0f;
  774.               commisions[30]= fee;
  775.             }
  776.             
  777.             {
  778.               double[] principles = { 2500.0f,
  779.                              6000.0f,
  780.                              22000.0f,
  781.                              50000.0f,
  782.                              500000.0f,
  783.                              9999999999.9f
  784.                          };
  785.               double[] bases = { 22.0f,
  786.                         38.0f,
  787.                         59.0f,
  788.                         77.0f,
  789.                         120.0f,
  790.                         205.0f
  791.                        };
  792.               double[] perc = {0.014f,
  793.                           0.0045f,
  794.                           0.0025f,
  795.                           0.0017f,
  796.                           0.00085f,
  797.                           0.00068f
  798.                         };
  799.               princ = shares * price;
  800.               if(price < 1.0f)
  801.                 fee = 37.0f + 0.03f * princ;
  802.               else {
  803.                 for(i = 0; i < 6; i++)
  804.                   if(principles[i] < princ)
  805.                 continue;
  806.                   else
  807.                 break;
  808.                 fee = bases[i] + perc[i] * princ;
  809.                 if(1000.0f < shares)
  810.                   min = 60.0f + 0.03f * (shares - 1000.0f);
  811.                 else
  812.                   min = 0.06f * shares;
  813.                 if(shares < 100.0f)
  814.                   max = 49.0f;
  815.                 else
  816.                   max = 49.0f + 0.5f * (shares - 100.0f);
  817.                 if(max < fee)
  818.                   fee = max;
  819.                 if(fee < min)
  820.                   fee = min;
  821.               };
  822.               if(fee < 37.5f)
  823.                 fee = 37.5f;
  824.               commisions[31]= fee;
  825.             }
  826.             
  827.             {
  828.               double[] principles = { 2500.0f,
  829.                              5000.0f,
  830.                              15000.0f,
  831.                              50000.0f,
  832.                              250000.0f,
  833.                              9999999999.9f
  834.                          };
  835.               double[] bases = { 25.0f,
  836.                         35.0f,
  837.                         50.0f,
  838.                         60.0f,
  839.                         100.0f,
  840.                         125.0f
  841.                        };
  842.               double[] perc = {0.016f,
  843.                           0.0084f,
  844.                           0.004f,
  845.                           0.003f,
  846.                           0.00125f,
  847.                           0.0011f
  848.                         };
  849.               princ = shares * price;
  850.               for(i = 0; i < 6; i++)
  851.                 if(principles[i] < princ)
  852.                   continue;
  853.                 else
  854.                   break;
  855.               fee = bases[i] + perc[i] * princ;
  856.               max = 0.48f * shares;
  857.               if(max < fee)
  858.                 fee = max;
  859.               if(fee < 40.0f)
  860.                 fee = 40.0f;
  861.               commisions[32]= fee;
  862.             }
  863.         } catch(NumberFormatException e) {
  864.             for(i = 0; i < number_of_brokers; i++)
  865.                 commisions[i] = -1.0f;
  866.         }        
  867.     }
  868.     public void compute_options() {
  869.             double price, shares;
  870.         double fee, princ, min, max;
  871.         int i;
  872.         try {
  873.             price_obj.setText(price_obj.getText().replace(',', '.'));
  874.             shares_obj.setText(shares_obj.getText().replace(',', '.'));
  875.             price = Double.valueOf(price_obj.getText()).doubleValue();
  876.             shares = Double.valueOf(shares_obj.getText()).doubleValue();
  877.  
  878.             {
  879.               if(shares < 10.0f)
  880.                 fee = 25.0f + 2.5f * shares;
  881.               else
  882.                 fee = 47.5f + 2.0f * (shares - 10.0f);
  883.               fee = fee + 2.50f;
  884.               commisions[1] = fee;
  885.             }
  886.             
  887.             {
  888.               if(price < 1.00f) {
  889.                 if(shares <= 10.0f)
  890.                   fee = 3.00f * shares;
  891.                 if((10.0f < shares) && (shares <= 30.0f)) 
  892.                   fee = 2.00f * (shares - 10) + 30.00f;
  893.                 if(30.0f < shares)
  894.                   fee = 1.50f * (shares - 30) + 70.00f;
  895.               }
  896.               if((1.00f <= price) && (price < 2.00f)) {
  897.                 if(shares <= 10.0f)
  898.                   fee = 3.50f * shares;
  899.                 if((10.0f < shares) && (shares <= 30.0f))
  900.                   fee = 2.00f * (shares - 10) + 35.00f;
  901.                 if(30.0f < shares)
  902.                   fee = 1.50f * (shares - 30) + 75.00f;
  903.               }
  904.               if((2.00f <= price) && (price < 3.00f)) {
  905.                 if(shares <= 10.0f) 
  906.                   fee = 4.50f * shares;
  907.                 if((10.0f < shares) && (shares <= 30.0f))
  908.                   fee = 2.50f * (shares - 10) + 45.00f;
  909.                 if(30.0f < shares)
  910.                   fee = 2.00f * (shares - 30) + 95.00f;
  911.               }
  912.               if((3.00f <= price) && (price < 4.00f)) {
  913.                 if(shares <= 10.0f)
  914.                   fee = 5.50f * shares;
  915.                 if((10.0f < shares) && (shares <= 30.0f))
  916.                   fee = 3.00f * (shares - 10) +  55.00f;
  917.                 if(30.0f < shares)
  918.                   fee = 2.50f * (shares - 30) + 115.00f;
  919.               }
  920.               if((4.00f <= price) && (price < 5.00f)) {
  921.                 if(shares <= 10.0f)
  922.                   fee = 6.50f * shares;
  923.                 if((10.0f < shares) && (shares <= 30.0f))
  924.                   fee = 3.50f * (shares - 10) +  65.00f;
  925.                 if(30.0f < shares)
  926.                   fee = 3.00f * (shares - 30) + 135.00f;
  927.               }
  928.               if(5.00f <= price) {
  929.                 if(shares <= 10.0f)
  930.                   fee = 7.50f * shares;
  931.                 if((10.0f < shares) && (shares <= 30.0f))
  932.                   fee = 4.50f * (shares - 10) +  75.00f;
  933.                 if(30.0f < shares)
  934.                   fee = 3.50f * (shares - 30) + 165.00f;
  935.               }
  936.               if(fee < 21.00f)
  937.                 fee = 21.00f;
  938.               commisions[3] = fee;
  939.             }
  940.             
  941.             {
  942.               fee = 1.75f * shares;
  943.               if(1.00f < price) 
  944.                 fee = 3.00f * shares;
  945.               if(fee < 25.00f) 
  946.                 fee = 25.00f;
  947.               fee = fee + 2.50f;      
  948.               commisions[7] = fee;
  949.             }
  950.             
  951.             {
  952.               fee = 25.00f + 2.50f * shares;
  953.               commisions[9] = fee;
  954.             }
  955.             
  956.             {
  957.               if(price < 0.50f) {
  958.                 if(shares <= 10.0f) 
  959.                   fee = 2.50f * shares;
  960.                 if((10.0f < shares) && (shares < 50.0f))
  961.                   fee = 2.00f * shares;
  962.                 if(50.0f < shares)
  963.                   fee = 1.50f * shares;
  964.               }
  965.               if((0.50f <= price) && (price < 2.00f)) {
  966.                 if(shares <= 10.0f) 
  967.                   fee = 3.50f * shares;
  968.                 if((10.0f < shares) && (shares < 50.0f))
  969.                   fee = 2.50f * shares;
  970.                 if(50.0f < shares)
  971.                   fee = 1.75f * shares;
  972.               }
  973.               if((2.00f <= price) && (price < 4.00f)) {
  974.                 if(shares <= 10.0f) 
  975.                   fee = 3.75f * shares;
  976.                 if((10.0f < shares) && (shares < 50.0f))
  977.                   fee = 3.00f * shares;
  978.                 if(50.0f < shares)
  979.                   fee = 2.50f * shares;
  980.               }
  981.               if((4.00f <= price) && (price < 8.00f)) {
  982.                 if(shares <= 10.0f) 
  983.                   fee = 4.75f * shares;
  984.                 if((10.0f < shares) && (shares < 50.0f))
  985.                   fee = 4.00f * shares;
  986.                 if(50.0f < shares)
  987.                   fee = 3.00f * shares;
  988.               }
  989.               if(8.00f <= price) {
  990.                 if(shares <= 10.0f) 
  991.                   fee = 6.25f * shares;
  992.                 if((10.0f < shares) && (shares < 50.0f))
  993.                   fee = 5.25f * shares;
  994.                 if(50.0f < shares)
  995.                   fee = 5.00f * shares;
  996.               }
  997.               if(fee < 25.00f) 
  998.                 fee = 25.00f;
  999.               fee = fee + 4.00f;
  1000.               commisions[10] = fee;
  1001.             }
  1002.                
  1003.             {
  1004.               if(price < 2.00f) {
  1005.                 if(shares <= 10.0f)
  1006.                   fee = 3.00f * shares;
  1007.                 if((10.0f < shares) && (shares <= 30.0f) )
  1008.                    fee = 2.00f * (shares - 10) + 30.00f;
  1009.                 if(30.0f < shares)
  1010.                   fee = 1.50f * (shares - 30) + 70.00f;
  1011.               }
  1012.               if((2.00f <= price) && (price < 4.00f)) {
  1013.                 if(shares <= 10.0f)
  1014.                   fee = 4.50f * shares;
  1015.                 if((10.0f < shares) && (shares <= 30.0f))
  1016.                    fee = 2.50f * (shares - 10) +  45.00f;
  1017.                 if(30.0f < shares)
  1018.                   fee = 2.00f * (shares - 30) +  95.00f;
  1019.               }
  1020.               if((4.00f <= price) && (price < 8.00f)) {
  1021.                 if(shares <= 10.0f)
  1022.                   fee = 6.50f * shares;
  1023.                 if((10.0f < shares) && (shares <= 30.0f))
  1024.                    fee = 3.50f * (shares - 10) +  65.00f;
  1025.                 if(30.0f < shares)
  1026.                   fee = 3.00f * (shares - 30) + 135.00f;
  1027.               }
  1028.               if(8.00f <= price) {
  1029.                 if(shares <= 10.0f)
  1030.                   fee = 8.00f * shares;
  1031.                 if((10.0f < shares) && (shares <= 30.0f))
  1032.                    fee = 6.00f * (shares - 10) +  80.00f;
  1033.                 if(30.0f < shares)
  1034.                   fee = 5.00f * (shares - 30) + 200.00f;
  1035.               }
  1036.               if(fee < 35.00f) 
  1037.                 fee = 35.00f;
  1038.               commisions[14] = fee;
  1039.             }
  1040.             
  1041.             {
  1042.               if(price < 2.00f) {
  1043.                 if(shares <= 10.0f)
  1044.                   fee = 3.00f * shares;
  1045.                 if((10.0f < shares) && (shares <= 30.0f))
  1046.                   fee = 2.00f * (shares - 10.0f) + 30.00f;
  1047.                 if(30.0f < shares)
  1048.                   fee = 1.50f * (shares - 30.0f) + 70.00f;
  1049.               }
  1050.               if((2.00f <= price) && (price < 4.00f)) {    
  1051.                 if(shares <= 10.0f)
  1052.                   fee = 4.50f * shares;
  1053.                 if((10.0f < shares) && (shares <= 30.0f))
  1054.                   fee = 2.50f * (shares - 10.0f) + 45.00f;
  1055.                 if(30.0f < shares)
  1056.                   fee = 2.00f * (shares - 30.0f) + 95.00f;
  1057.               }
  1058.               if(4.00f <= price) {
  1059.                 if(shares <= 10.0f)
  1060.                   fee = 5.50f * shares;
  1061.                 if((10.0f < shares) && (shares <= 30.0f))
  1062.                   fee = 3.50f * (shares - 10.0f) +  55.00f;
  1063.                 if(30.0f < shares)
  1064.                   fee = 3.00f * (shares - 30.0f) + 125.00f;
  1065.               }
  1066.               if(fee < 30.00f)
  1067.                 fee = 30.00f; 
  1068.               fee = fee + 3.00f;
  1069.               commisions[15] = fee;
  1070.             }
  1071.             
  1072.             {
  1073.               fee = 20.00f + 1.50f * shares;
  1074.               if(1.00f <= price)
  1075.                 fee = 20.00f + 2.00f * shares;
  1076.               if(fee < 40.00f)
  1077.                 fee = 40.00f;
  1078.               commisions[16] = fee;
  1079.             }
  1080.             
  1081.             {
  1082.               fee = 30.00f;
  1083.               if(price < 1.00f) 
  1084.                 fee += 1.00f * shares;
  1085.               if((1.00f <= price) && (price < 4.00f))
  1086.                 fee += 2.00f * shares;
  1087.               if((4.00f <= price) && (price < 7.00f))
  1088.                 fee += 3.00f * shares;
  1089.               if(7.00f <= price)
  1090.                 fee += 4.00f * shares;
  1091.               commisions[17] = fee;
  1092.             }
  1093.             
  1094.             {
  1095.               fee = 20.00f;
  1096.               if(price < 1.00f) 
  1097.                 fee += 1.00f * shares;
  1098.               if((1.00f <= price) && (price < 4.00f))
  1099.                 fee += 2.00f * shares;
  1100.               if((4.00f <= price) && (price < 7.00f))
  1101.                 fee += 3.00f * shares;
  1102.               if(7.00f <= price)
  1103.                 fee += 4.00f * shares;
  1104.               commisions[18] = fee;
  1105.             }
  1106.             
  1107.             {
  1108.               fee = 29.0f;
  1109.               if(5.0f < shares)
  1110.                 fee = fee + 1.50f * (shares - 5.0f); 
  1111.               commisions[19] = fee;
  1112.             }
  1113.             
  1114.             {
  1115.               if(price < 1.00f)
  1116.                 fee = 40.00f + 1.50f * shares;
  1117.               else
  1118.                 fee = 40.00f + 2.00f * shares;
  1119.               commisions[20] = fee;
  1120.             }
  1121.             
  1122.             {
  1123.               fee = 2.00f * shares;
  1124.               if(0.50f < price)
  1125.                 fee = 3.75f * shares;
  1126.               if(fee < 50.0f)
  1127.                 fee = 50.0f;
  1128.               commisions[22] = fee;
  1129.             }
  1130.             
  1131.             {
  1132.               fee = 3.00f * shares;
  1133.               if(4.00f <= price)
  1134.                 fee = 4.00f * shares;
  1135.               if(fee < 35.00f)
  1136.                 fee = 35.00;
  1137.               commisions[24] = fee;
  1138.             }
  1139.             
  1140.             {
  1141.               fee = 27.00f + 3.00f * shares;
  1142.               commisions[25] = fee;
  1143.             }
  1144.  
  1145.         } catch(NumberFormatException e) {
  1146.             for(i = 0; i < number_of_brokers; i++)
  1147.                 commisions[i] = -1.0;
  1148.                 }
  1149.     }
  1150.         public boolean action(Event e, Object dummy) {
  1151.          compute();
  1152.         return(true);
  1153.     }
  1154.     public String getAppletInfo() {
  1155.         return("Robert's Online Commissions Pricer! by Dr. Robert Lum");
  1156.     }
  1157. }
  1158.